package proj.euler;

public class P2 {
	
		public static int f(int i) {
			if (i == 1 || i == 2 || i == 3)
				return i;
			else
				return f(i - 1) + f(i - 2);
		}
	
		public static int limitLastIndex(int limit) {
			if (limit == 1 || limit == 2 || limit == 3)
				return limit;
	
			int i = 4;
			int fb = 5;
			while (fb <= limit) {
				++i;
				fb = f(i);
			}
			return i - 1;
		}
	
		public static int evenSumInLimit(int limit) {
			int i = limitLastIndex(limit);
			int sum = 0;
			for (int j = 2; j <= i; ++j) {
				int fb = f(j);
				if (fb % 2 == 0) {
					sum += fb;
				}
			}
			return sum;
		}

}
